﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kooboo;

namespace KB
{
    public class ContextUtility
    {
        public static T Get<T>(string key)
        {
            return CallContext.Current.GetObject<T>(key);
        }

        public static void Add<T>(string key, T value)
        {
            CallContext.Current.RegisterObject<T>(key, value);
        }

        public static T GetOrAdd<T>(string key, Func<T> creator)
        {
            T value = Get<T>(key);
            if (value == null)
            {
                value = creator();
                Add(key, value);
            }

            return value;
        }
    }
}